<?php
namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;

class Install extends Command
{
    protected function configure()
    {
        $this->setName('install')
            ->setDescription('Install the application');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            // 创建数据表
            $sql_files = glob(ROOT_PATH . 'database/migrations/*.sql');
            foreach ($sql_files as $file) {
                $sql = file_get_contents($file);
                Db::execute($sql);
            }
            
            // 创建上传目录
            $upload_paths = config('app.upload.path');
            foreach ($upload_paths as $path) {
                if (!is_dir(ROOT_PATH . 'public/' . $path)) {
                    mkdir(ROOT_PATH . 'public/' . $path, 0755, true);
                }
            }
            
            $output->writeln('Installation completed successfully!');
        } catch (\Exception $e) {
            $output->writeln('Installation failed: ' . $e->getMessage());
        }
    }
}